from typing import List


class Solution:
    ## 使用二分方法
    def searchRange(self, nums: List[int], target: int) -> List[int]:
        res = [-1, -1]
        if len(nums) == 0:
            return res
        
        left, right = 0, len(nums)-1
        while left<=right: ## 这里需要注意是否等于
            mid  = left + (right-l)//2

            if nums[mid] == target:
                ## 向前后搜索
                ### 向前搜索
                i=mid
                while i>0 and nums[i-1] == target:
                    i -= 1
                
                j = mid
                while  j<len(nums)-1 and nums[j+1]==target:
                    j+=1
                
                return [i, j]
            elif nums[mid]<target:
                left = mid + 1
            else:
                right = mid -1
        return res